package com.silverhaze.diamond.common.event;

import com.silverhaze.commons.db.datasource.ObjectEntity;

import java.io.Serializable;

/**
 * This code is part of Kg.Axion project. Treat as strictly confidential.
 * Author: Ivan Babanin
 * Creation date: 18.08.2010 13:08:34
 */
public abstract class UIEvent implements Serializable {
    protected boolean serverEvent;

    public abstract boolean isMergeable();

    public abstract void merge(UIEvent event);

    public abstract boolean canMergeWith(UIEvent event);

    public abstract Class<? extends ObjectEntity> getChangedEntityClass();

    public void setServerEvent(boolean serverEvent) {
        this.serverEvent = serverEvent;
    }

    public boolean isServerEvent() {
        return serverEvent;
    }

    public boolean isAnyClassChanged(Class... classes) {
        Class changedEntityClass = getChangedEntityClass();

        if (changedEntityClass != null) {
            for (Class aClass : classes) {
                if(changedEntityClass.equals(aClass)){
                    return true;
                }
            }
        }

        return false;
    }

    public abstract String toString();
}